/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package clientereligadora.conexao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import javax.swing.JOptionPane;

/**
 *
 * @author leandro.aquino
 */
public class Conexao {

    public boolean status = true;
    private PreparedStatement stmt;
    public static Connection conn;

    static {
        try {

            //especifico o driver a ser usado
            Class.forName("com.mysql.jdbc.Driver");

        } catch (ClassNotFoundException e) {
        }
    }

    public Conexao(String host, String porta, String dataBase, String user, String pass) {

        try {
            conn = DriverManager.getConnection("jdbc:mysql://" + host + ":" + porta + "/" + dataBase, user, pass);
            System.out.println("Conectado..");
        } catch (Exception ex) {
            System.out.println(ex);
            JOptionPane.showMessageDialog(null, "O servidor especidicado não foi encontrado\nFavor verificar"
                    + "configuração", "Erro de Conexão ao Banco de Dados", JOptionPane.ERROR_MESSAGE);
            status = false;
            System.exit(0);
        }


    }

    public boolean getStatus() {
        return status;
    }

    public void finalisarConecxao() {
        try {
            conn.close();
        } catch (Exception ex) {
        }
    }
}
